/////////////////
//  PREAMBLE  //
////////////////

/*	program:	Figure-1.do
	author:		David Bateman */
/******************************************************************************/
/*** 																		***/
/*** File opens up the suffrage database and converts the various suffrage  ***/
/*** classes into property, taxpaying, racial and gender qualifications. 	***/
/*** 																		***/
/*** The property and tax qualifications are those which applied to the 	***/
/*** primary class through which persons became eligible to vote. 			***/
/***																		***/
/*** This means that if a property qualification was in place, but 			***/
/*** an alternative such as residency or literacy was available, that the 	***/
/*** state is not coded as having an effective qualification for the primary***/
/*** class of voters. For this analysis, it is white native born men.		***/
/*** 																		***/
/*** If a state has no property/tax, and no racial or nativity qualification***/
/*** then the coding for white native born men reduces to the coding for 	***/
/*** all men.																***/
/*** 																		***/
/******************************************************************************/

cd "..\..\Dataverse\"
use "Data\Suffrage-1780-1933.dta", clear
set more off
xtset icpsrstate

*** Miscellaneous
*** Keep only territories with a territorial legislature in place
drop if territoriallegislature==0 | (statehood==0 & territoriallegislature==.)
*** In 1867 Congress passed Territorial Suffrage Act
	replace racial_exclusion = 0 if statehood==0 & year>=1867 & year<=1870
*** Georgia didn't have an explicit restriction in suffrage laws but no evidence free Black Georgians allowed to vote
	replace racial_exclusion = 1 if icpsrstate==44 & year>=1789 & year<=1861

/******************************************************************************* 
*** The suffrage dataset includes several bases for disenfranchisement, including
*** many that create different classes within an otherwise common category. These
*** include qualifications that allow men to vote if they own property, or if they
*** can pass a literacy test as an alternative. Each state is coded as having either
*** one (c1) or two (c2) such classes. The different class bases are coded
*** as follows:

1 = Property: c1 = property, c2 = tax, militia, or residence alternative
2 = Bicameralism: c1 = most popular chamber
3 = Race: c1 = whites
4 = Citizenship: c1 = citizens
5 = Residence: c1 = Longer residence in state, c2 = shorter residence in county
6 = Nativity: c1 = native born
7 = Occupation: c1 = Non-occupational exemption, c2 = occupational exemption
8 = Urban/Freemanship: c1 = rural/non-freemanship
9 = Settlement: c1 = settlement made on land
10 = Literacy: c1 = literate
11 = Veteran status: c1 = non-veteran

The "primary_class" indicates which class of voters would be the most common
basis for enfranchisement. The "Class Suffrage" in Figure 1 focuses oh native
born white men.
*/
******************************************************************************* 

capture label drop class_basis
label define class_basis 1 "Property, w. Tax, Militia, or Residence Alternative"
label define class_basis 2 "Bicameral Distinction", add
label define class_basis 3 "Race", add
label define class_basis 4 "Citizenship", add
label define class_basis 5 "Residence", add
label define class_basis 6 "Nativity", add
label define class_basis 7 "Occupation", add
label define class_basis 8 "Urban/Freemanship", add
label define class_basis 9 "Settlement", add
label define class_basis 10 "Literacy", add
label define class_basis 11 "Veteran Status", add
label values class_basis class_basis

capture label drop citizenship_exclusion
label define citizenship_exclusion 0 "No Citizenship Specified"
label define citizenship_exclusion 1 "US Citizenship Required", add
label define citizenship_exclusion 2 "Qualified (Inclusive)", add
label define citizenship_exclusion 3 "Qualified (Exclusion)", add
label values citizenship_exclusion citizenship_exclusion

capture label drop gender_exclusion
label define gender_exclusion 0 "No Gender Specified"
label define gender_exclusion 1 "Male Specified", add
label define gender_exclusion 2 "Qualified (Inclusive)", add
label values gender_exclusion gender_exclusion


*** Property requirements for white male native born citizens to vote
gen whnb_property = any_property if (class_basis!=3 | class_basis!=4 | class_basis!=6 | class_basis!=2)
replace whnb_property = c1_property if n_classes_voters==1
replace whnb_property = c1_property if (class_basis==3 | class_basis==4 | class_basis==6 )

capture label drop whnb_property
label define whnb_property 0 "No Property for White Male Native Born Citizens"
label define whnb_property 1 "Property for White Male Native Born Citizens", add
label values whnb_property whnb_property

*** Many of these were not effective, ie. they allowed for exceptions on basis of literacy
*** or payment of taxes or residency. 

/*	Is there an effective property exclusion for white native born citizens. 	*/
gen whnb_property_effective = c1_property if (class_basis==3 | class_basis==4 | class_basis==6 | class_basis==7 | class_basis==8 | class_basis==9 | class_basis==10 | class_basis==11)
replace whnb_property_effective = c1_property if n_classes_voters==1
replace whnb_property_effective = c2_property if (class_basis==1 | class_basis==5 | class_basis==2)

capture label drop whnb_property_effective
label define whnb_property_effective 0 "No Property for White Male Native Born Citizens"
label define whnb_property_effective 1 "Effective Property Qual. for White Male Native Born Citizens", add
label values whnb_property_effective whnb_property_effective
	
*** Tax requirements for white male native born citizens to vote
		
gen whnb_taxpayer = c1_tax if (class_basis==2 |class_basis==3 | class_basis==4 | class_basis==6 | class_basis==7 | class_basis==8 | class_basis==9 | class_basis==10 | class_basis==11)
replace whnb_taxpayer = c1_tax if n_classes_voters==1
replace whnb_taxpayer = c2_tax if (class_basis==1 | class_basis==5)

capture label drop whnb_taxpayer
label define whnb_taxpayer 0 "No Tax Qual. for White Male Native Born Citizens"
label define whnb_taxpayer 1 "Tax Qual. for White Male Native Born Citizens", add
label values whnb_taxpayer whnb_taxpayer
	
*** Is there a pecuniary requirement (tax or effective property) for white native born citizens
gen whnb_pecun_effective = 1 if whnb_property_effective==1
replace whnb_pecun_effective = 1 if whnb_taxpayer==1
replace whnb_pecun_effective = 0 if whnb_property_effective==0 & whnb_taxpayer==0

capture label drop whnb_pecun_effective
label define whnb_pecun_effective 0 "No Pecuniary Qual. for White Male Native Born Citizens"
label define whnb_pecun_effective 1 "Pecuniary Qual. for White Male Native Born Citizens", add
label values whnb_pecun_effective whnb_pecun_effective

*** Is gender a listed requirement for voting? Is gender not required for some offices/races?
gen gender_exclusion1 = gender_exclusion
replace gender_exclusion1 = 0 if gender_exclusion==2
gen gender_exclusion2 = gender_exclusion
replace gender_exclusion2 = 0 if gender_exclusion==1
replace gender_exclusion2 = 1 if gender_exclusion==2

preserve
	keep whnb_property_effective whnb_taxpayer state year icpsrstate
	keep if year>=1789 & year<=1860
	save "Data\Suffrage-Reduced.dta", replace
restore
	

*** Create figure of over time trends	
collapse (count) icpsrstate (sum) whnb_property_effective whnb_property whnb_pecun_effective racial_exclusion race_neutral_exclusion gender_exclusion1 gender_exclusion2, by(year)
rename icpsrstate states
gen perEffectiveProperty = (whnb_property_effective/states)*100
gen perPecuniary = (whnb_pecun_effective/states)*100
gen perRacial = (racial_exclusion/states)*100
gen perRacial_target = (race_neutral_exclusion/states)*100
gen perGender1 = (gender_exclusion1/states)*100
gen perGender2 = (gender_exclusion2/states)*100
	
*** Property
twoway  (line perEffectiveProperty year, lc(black) lw(medthin) lp(solid ) connect(J)) ///
		(line perPecuniary year, ///
			lc(black) lw(medthin) lp(longdash ) connect(J)) ///
		, graphregion(color(white)) xtitle("", size(vsmall)) ///
		ytitle("", size(small)) ///
		ylab(#10, nogrid angle(h) labsize(vsmall)) ///
		xlab(#20, angle(h) labsize(vsmall)) ///
		yscale(range(0 100) )	xscale(range(`first_year' `last_year') )			///
		title("Class Suffrage", ///
			size(small) color(black)) ///
		legend(order(1 2)  col(5)  	///
			label(1 "Property Qualification") ///
			label(2 "Taxpaying or Property Qualification") ///
			size(vsmall) keygap(tiny) rowgap(tiny) 	///
			colgap(tiny) symxsize(huge) region(color(none) fcolor(none)))	///
		name(graph1, replace)

twoway  (line perRacial  year, lc(black) lw(medthin) lp(solid ) connect(J)) ///
		(line perRacial_target year, ///
			lc(black) lw(medthin) lp(longdash ) connect(J)) ///
		, graphregion(color(white)) xtitle("", size(vsmall)) ///
		ytitle("", size(small)) ///
		ylab(#10, nogrid angle(h) labsize(vsmall)) ///
		xlab(#20, angle(h) labsize(vsmall)) ///
		yscale(range(0 100) )	xscale(range(`first_year' `last_year') )			///
		title("Racial Suffrage", ///
			size(small) color(black)) ///
		legend(order(1 2)  col(5)  	///
			label(1 "Racial Qualification") ///
			label(2 "Targeted Racial Disenfranchisement") ///
			size(vsmall) keygap(tiny) rowgap(tiny) 	///
			colgap(tiny) symxsize(huge) region(color(none) fcolor(none)))	///
		name(graph2, replace)

twoway  (line perGender1  year, lc(black) lw(medthin) lp(solid ) connect(J)) ///
		(line perGender2 year, ///
			lc(black) lw(medthin) lp(longdash ) connect(J)) ///
		, graphregion(color(white)) xtitle("", size(vsmall)) ///
		ytitle("", size(small)) ///
		ylab(#10, nogrid angle(h) labsize(vsmall)) ///
		xlab(#20, angle(h) labsize(vsmall)) ///
		yscale(range(0 100) )	xscale(range(`first_year' `last_year') )			///
		title("Woman Suffrage", ///
			size(small) color(black)) ///
		legend(order(1 2)  col(5)  	///
			label(1 "Gender Qualification") ///
			label(2 "Partial Gender Qualification") ///
			size(vsmall) keygap(tiny) rowgap(tiny) 	///
			colgap(tiny) symxsize(huge) region(color(none) fcolor(none)))	///
		name(graph3, replace)

graph combine graph1 graph2 graph3, rows(3) graphreg(col(white)) note(Percent of states and territories with qualification, size(vsmall))
graph display, xsize(8.5) ysize(11)
graph export "Figures/Figure-1.pdf", replace

********************************************************************************
